module helper {

    export class Helper {

        public constructor() {

        }

        public static createBitmapByName(name: string): egret.Bitmap {
            let result: egret.Bitmap = new egret.Bitmap();
            let texture: egret.Texture = RES.getRes(name);
            result.texture = texture;
            return result;
        }

        public static removeFromParent(children: egret.DisplayObject): void {
            if (children != null && children.parent != null) {
                children.parent.removeChild(children);
            }
        }

        public static getRand(length: number): number {
            let rand: number = Math.random() * 9999999;
            rand = parseInt(rand + "");
            rand = rand % length;
            return rand;
        }

        public static clone(obj: any): any {
            return JSON.parse(JSON.stringify(obj));
        }

        public static previewImg(imgUrl:string):void {
            wx.previewImage({
                current: imgUrl,
                urls: [imgUrl],
                success: function (res) {
                },
                fail: function (res) {
                },
                complete: function (res) {
                },
            });
        }

        public static compareVersion(v1, v2) {
            v1 = v1.split('.')
            v2 = v2.split('.')
            var len = Math.max(v1.length, v2.length)

            while (v1.length < len) {
                v1.push('0')
            }
            while (v2.length < len) {
                v2.push('0')
            }
            v1 = Number(v1.join(''));
            v2 = Number(v2.join(''));
            if (v1 && v2 && v1 >= v2) return 1
            return 0
        }

    }

}